home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-01-19 | 64.3 KB | 2,489 lines |
- Newsgroups: comp.sources.misc
- subject: v10i027: B+tree library, part01 of 5
- from: mjr@umiacs.UMD.EDU (Marcus J. Ranum)
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 10, Issue 27
- Submitted-by: mjr@umiacs.UMD.EDU (Marcus J. Ranum)
- Archive-name: b+tree_mjr/part01
-
- This is the source code for a variable-length key variable
- page size b+tree library. Also included is source for a variety of
- test programs, a semi-useable record manager, and a dbm-lookalike
- library built on top of the record manager and b+tree. (dbm(3) will
- blow it away performance-wise, of course).
-
- This software has been tested (and works) on the following:
- Pyramid/OSx, Sun4/SunOs, Sun3/SunOs, Digital Vax/BSD4.3,
- Digital DECstation3100/Ultrix
-
- This software has been tested and found NOT to work on the
- following:
- SCO Xenix - I have no idea why because I don't have one
-
-
- Contents::
- ----------------------------------------------------------------------
- COPYRIGHT - licensing/copyright notice. read it, please.
-
- Makefile - makefile
-
- btlib - source for the b+tree library. directions for
- compilation are in btlib/README.
-
- doc - manual pages for the b+tree library
-
- btdbmlib - source for a sort of record management library
- that is pretty much of a "toy" library, and will
- probably not cut it for serious projects unless it
- is beefed-up a bit. Also includes source for a
- dbm-clone library that uses b+tree indexes.
- the record manager was designed for an application
- I wrote that demanded being able to store things
- of practically any size, and did not require high
- performance. if you are trying to write a real
- database, please don't waste your time even looking
- at it.
-
- utils - utility programs and toys, including test-rack
- software for the b+tree
-
- --slicez--dicez--choppez--shreddez--slicez--dicez--choppez--shreddez--slicez--
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 5)."
- # Contents: b+tree b+tree/Makefile b+tree/README b+tree/btdbmlib
- # b+tree/btdbmlib/btdbm.h b+tree/btdbmlib/btdbmclose.c
- # b+tree/btdbmlib/btdbmdelete.c b+tree/btdbmlib/btdbmfetch.c
- # b+tree/btdbmlib/btdbmfirstkey.c b+tree/btdbmlib/btdbmnextkey.c
- # b+tree/btdbmlib/btdbmopen.c b+tree/btdbmlib/btdbmstore.c
- # b+tree/btdbmlib/stclose.c b+tree/btdbmlib/stcopy.c
- # b+tree/btdbmlib/stdecref.c b+tree/btdbmlib/sterrs.c
- # b+tree/btdbmlib/stgethed.c b+tree/btdbmlib/stincref.c
- # b+tree/btdbmlib/stlinka.c b+tree/btdbmlib/stoconf.h
- # b+tree/btdbmlib/stointern.h b+tree/btdbmlib/stopen.c
- # b+tree/btdbmlib/stputhed.c b+tree/btdbmlib/stread.c
- # b+tree/btdbmlib/streallocbuf.c b+tree/btdbmlib/stunlink.c
- # b+tree/btdbmlib/stwrite.c b+tree/btdbmlib/stwsuper.c b+tree/btlib
- # b+tree/btlib/Makefile b+tree/btlib/btclose.c
- # b+tree/btlib/bterrors.c b+tree/btlib/btfind.c
- # b+tree/btlib/btgoto.c b+tree/btlib/btlabel.c b+tree/btlib/btseek.c
- # b+tree/btlib/btzap.c b+tree/doc b+tree/doc/Makefile b+tree/utils
- # b+tree/utils/flog.sh b+tree/utils/words.c
- # Wrapped by mjr@atreus on Fri Jan 19 10:34:57 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test ! -d 'b+tree' ; then
- echo shar: Creating directory \"'b+tree'\"
- mkdir 'b+tree'
- fi
- if test -f 'b+tree/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/Makefile'\"
- else
- echo shar: Extracting \"'b+tree/Makefile'\" \(855 characters\)
- sed "s/^X//" >'b+tree/Makefile' <<'END_OF_FILE'
- X#
- X#
- X#/*
- X# (C) Copyright, 1988, 1989 Marcus J. Ranum
- X# All rights reserved
- X#
- X#
- X# This software, its documentation, and supporting
- X# files are copyrighted material and may only be
- X# distributed in accordance with the terms listed in
- X# the COPYRIGHT document.
- X#*/
- X#
- X# $Header: /atreus/mjr/hacks/btree/Makefile,v 1.1 89/10/24 10:09:36 mjr Rel $
- X#
- X
- XMAKE= make
- X
- XLIB= libbtree.a
- X
- XSRCDIR= /users/mjr/hacks/btree
- X
- Xall:
- X cd btlib; $(MAKE)
- X cd btdbmlib; $(MAKE)
- X cd utils; $(MAKE)
- X cd doc; $(MAKE)
- X
- Xclean:
- X cd btlib; $(MAKE) clean
- X cd btdbmlib; $(MAKE) clean
- X cd utils; $(MAKE) clean
- X cd doc; $(MAKE) clean
- X
- Xci:
- X cd btlib; $(MAKE) ci
- X cd btdbmlib; $(MAKE) ci
- X cd utils; $(MAKE) ci
- X cd doc; $(MAKE) ci
- X ci -u Makefile README < /dev/null
- X
- Xlint:
- X cd btlib; $(MAKE) lint
- X cd btdbmlib; $(MAKE) lint
- END_OF_FILE
- if test 855 -ne `wc -c <'b+tree/Makefile'`; then
- echo shar: \"'b+tree/Makefile'\" unpacked with wrong size!
- fi
- # end of 'b+tree/Makefile'
- fi
- if test -f 'b+tree/README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/README'\"
- else
- echo shar: Extracting \"'b+tree/README'\" \(1489 characters\)
- sed "s/^X//" >'b+tree/README' <<'END_OF_FILE'
- X
- X This is the source code for a variable-length key variable
- Xpage size b+tree library. Also included is source for a variety of
- Xtest programs, a semi-useable record manager, and a dbm-lookalike
- Xlibrary built on top of the record manager and b+tree. (dbm(3) will
- Xblow it away performance-wise, of course).
- X
- X This software has been tested (and works) on the following:
- XPyramid/OSx, Sun4/SunOs, Sun3/SunOs, Digital Vax/BSD4.3,
- XDigital DECstation3100/Ultrix
- X
- X This software has been tested and found NOT to work on the
- Xfollowing:
- XSCO Xenix - I have no idea why because I don't have one
- X
- X
- XContents::
- X----------------------------------------------------------------------
- XCOPYRIGHT - licensing/copyright notice. read it, please.
- X
- XMakefile - makefile
- X
- Xbtlib - source for the b+tree library. directions for
- X compilation are in btlib/README.
- X
- Xdoc - manual pages for the b+tree library
- X
- Xbtdbmlib - source for a sort of record management library
- X that is pretty much of a "toy" library, and will
- X probably not cut it for serious projects unless it
- X is beefed-up a bit. Also includes source for a
- X dbm-clone library that uses b+tree indexes.
- X the record manager was designed for an application
- X I wrote that demanded being able to store things
- X of practically any size, and did not require high
- X performance. if you are trying to write a real
- X database, please don't waste your time even looking
- X at it.
- X
- Xutils - utility programs and toys, including test-rack
- X software for the b+tree
- END_OF_FILE
- if test 1489 -ne `wc -c <'b+tree/README'`; then
- echo shar: \"'b+tree/README'\" unpacked with wrong size!
- fi
- # end of 'b+tree/README'
- fi
- if test ! -d 'b+tree/btdbmlib' ; then
- echo shar: Creating directory \"'b+tree/btdbmlib'\"
- mkdir 'b+tree/btdbmlib'
- fi
- if test -f 'b+tree/btdbmlib/btdbm.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/btdbm.h'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/btdbm.h'\" \(1027 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/btdbm.h' <<'END_OF_FILE'
- X#ifndef _DEF_BTDBM_H
- X
- X#ifndef _DEF_BTREE_H
- X#include <btree.h>
- X#endif
- X
- X#ifndef _DEF_STO_H
- X#include <store.h>
- X#endif
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X/*
- X $Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/btdbm.h,v 1.1 89/10/24 10:09:19 mjr Rel $
- X*/
- X
- X#define BTDBM_INSERT 0
- X#define BTDBM_REPLACE 1
- X
- Xtypedef struct {
- X bt_chrp dptr;
- X int dsize;
- X} btdatum;
- X
- Xstruct btdbm {
- X BT_INDEX *bt;
- X STORE *st;
- X int errno;
- X};
- X#define BTDBM struct btdbm
- X
- X#define btdbm_error(db) (db->errno)
- X#define btdbm_clearerror(db) (db->errno = 0)
- X#define btdbm_btree(db) (db->bt)
- X#define btdbm_storefile(db) (db->bt)
- X
- Xextern BTDBM *btdbm_open();
- Xextern btdatum btdbm_fetch();
- Xextern btdatum btdbm_nextkey();
- Xextern btdatum btdbm_firstkey();
- X
- X#define _DEF_BTDBM_H
- X#endif
- END_OF_FILE
- if test 1027 -ne `wc -c <'b+tree/btdbmlib/btdbm.h'`; then
- echo shar: \"'b+tree/btdbmlib/btdbm.h'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/btdbm.h'
- fi
- if test -f 'b+tree/btdbmlib/btdbmclose.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/btdbmclose.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/btdbmclose.c'\" \(691 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/btdbmclose.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <btdbm.h>
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/btdbmclose.c,v 1.1 89/10/24 10:09:10 mjr Rel $";
- X#endif
- X
- X
- Xbtdbm_close(db)
- XBTDBM *db;
- X{
- X if(store_close(db->st) != STO_OK || bt_close(db->bt) != BT_OK) {
- X btdbm_error(db) = 1;
- X return(1);
- X }
- X btdbm_clearerror(db);
- X return(0);
- X}
- END_OF_FILE
- if test 691 -ne `wc -c <'b+tree/btdbmlib/btdbmclose.c'`; then
- echo shar: \"'b+tree/btdbmlib/btdbmclose.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/btdbmclose.c'
- fi
- if test -f 'b+tree/btdbmlib/btdbmdelete.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/btdbmdelete.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/btdbmdelete.c'\" \(853 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/btdbmdelete.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <btdbm.h>
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/btdbmdelete.c,v 1.1 89/10/24 10:09:10 mjr Rel $";
- X#endif
- X
- X
- Xbtdbm_delete(db,key)
- XBTDBM *db;
- Xbtdatum key;
- X{
- X off_t orrv;
- X
- X btdbm_error(db) = 1;
- X if(bt_find(db->bt,key.dptr,key.dsize,&orrv) == BT_NF)
- X return(1);
- X
- X /* free the record */
- X if(store_free(db->st,orrv) == STO_ERR)
- X return(1);
- X
- X /* clob the key */
- X if(bt_delete(db->bt,key.dptr,key.dsize) != BT_OK)
- X return(1);
- X
- X btdbm_clearerror(db);
- X return(0);
- X}
- END_OF_FILE
- if test 853 -ne `wc -c <'b+tree/btdbmlib/btdbmdelete.c'`; then
- echo shar: \"'b+tree/btdbmlib/btdbmdelete.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/btdbmdelete.c'
- fi
- if test -f 'b+tree/btdbmlib/btdbmfetch.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/btdbmfetch.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/btdbmfetch.c'\" \(1333 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/btdbmfetch.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <btdbm.h>
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/btdbmfetch.c,v 1.1 89/10/24 10:09:10 mjr Rel $";
- X#endif
- X
- X
- Xbtdatum
- Xbtdbm_fetch(db,key)
- XBTDBM *db;
- Xbtdatum key;
- X{
- X off_t orrv;
- X static btdatum ret;
- X struct sto_hdr hd;
- X
- X if(bt_find(db->bt,key.dptr,key.dsize,&orrv) == BT_NF)
- X goto bombout;
- X
- X /* OK - found a record */
- X /* 1) read its header info to see if it will fit in the buffer */
- X if(store_gethdr(db->st,orrv,&hd) == STO_ERR)
- X goto bombout;
- X
- X /* 2) if the internal buffer is not big enough, stretch it */
- X if(store_bufsiz(db->st) < hd.used)
- X if(store_reallocbuf(db->st,hd.used) == STO_ERR)
- X goto bombout;
- X
- X /* 3) read the stuff into the buffer and return it */
- X if(store_read(db->st,orrv,0L,store_buffer(db->st),store_bufsiz(db->st),&ret.dsize) != STO_OK)
- X goto bombout;
- X
- X ret.dptr = (bt_chrp)store_buffer(db->st);
- X
- X btdbm_clearerror(db);
- X return(ret);
- X
- Xbombout:
- X ret.dptr = 0;
- X ret.dsize = 0;
- X btdbm_error(db) = 1;
- X return(ret);
- X}
- END_OF_FILE
- if test 1333 -ne `wc -c <'b+tree/btdbmlib/btdbmfetch.c'`; then
- echo shar: \"'b+tree/btdbmlib/btdbmfetch.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/btdbmfetch.c'
- fi
- if test -f 'b+tree/btdbmlib/btdbmfirstkey.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/btdbmfirstkey.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/btdbmfirstkey.c'\" \(723 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/btdbmfirstkey.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <btdbm.h>
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/btdbmfirstkey.c,v 1.1 89/10/24 10:09:11 mjr Rel $";
- X#endif
- X
- X
- Xbtdatum
- Xbtdbm_firstkey(db)
- XBTDBM *db;
- X{
- X static btdatum ret;
- X
- X btdbm_error(db) = 1;
- X if(bt_goto(db->bt,BT_BOF) == BT_ERR) {
- X ret.dptr = 0;
- X ret.dsize = 0;
- X return(ret);
- X }
- X
- X ret = btdbm_nextkey(db);
- X return(ret);
- X}
- END_OF_FILE
- if test 723 -ne `wc -c <'b+tree/btdbmlib/btdbmfirstkey.c'`; then
- echo shar: \"'b+tree/btdbmlib/btdbmfirstkey.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/btdbmfirstkey.c'
- fi
- if test -f 'b+tree/btdbmlib/btdbmnextkey.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/btdbmnextkey.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/btdbmnextkey.c'\" \(965 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/btdbmnextkey.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <btdbm.h>
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/btdbmnextkey.c,v 1.1 89/10/24 10:09:11 mjr Rel $";
- X#endif
- X
- X
- Xbtdatum
- Xbtdbm_nextkey(db)
- XBTDBM *db;
- X{
- X static btdatum ret;
- X off_t rrv;
- X int r;
- X
- X r = bt_traverse(db->bt,BT_EOF,store_buffer(db->st),store_bufsiz(db->st),&ret.dsize,&rrv);
- X if(r == BT_ERR)
- X goto bombout;
- X
- X if(r == BT_EOF) {
- X ret.dptr = 0;
- X ret.dsize = 0;
- X btdbm_clearerror(db);
- X return(ret);
- X }
- X
- X ret.dptr = (bt_chrp)store_buffer(db->st);
- X
- X btdbm_clearerror(db);
- X return(ret);
- X
- Xbombout:
- X ret.dptr = 0;
- X ret.dsize = 0;
- X btdbm_error(db) = 1;
- X return(ret);
- X}
- END_OF_FILE
- if test 965 -ne `wc -c <'b+tree/btdbmlib/btdbmnextkey.c'`; then
- echo shar: \"'b+tree/btdbmlib/btdbmnextkey.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/btdbmnextkey.c'
- fi
- if test -f 'b+tree/btdbmlib/btdbmopen.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/btdbmopen.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/btdbmopen.c'\" \(1192 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/btdbmopen.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <btdbm.h>
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/btdbmopen.c,v 1.1 89/10/24 10:09:12 mjr Rel $";
- X#endif
- X
- X
- Xextern char *malloc();
- Xextern char *strcat();
- Xextern char *strcpy();
- X
- XBTDBM *
- Xbtdbm_open(path,type,flags,mode)
- Xchar *path;
- Xint type;
- Xint flags;
- Xint mode;
- X{
- X BTDBM *ret;
- X char nbuf[BUFSIZ];
- X
- X if((ret = (BTDBM *)malloc(sizeof(BTDBM))) == NULL)
- X return(NULL);
- X
- X (void)strcpy(nbuf,path);
- X (void)strcat(nbuf,".ndx");
- X
- X if((ret->bt = bt_optopen( BT_PATH, nbuf,
- X BT_DTYPE, type,
- X BT_OMODE, flags,
- X BT_OPERM, mode,
- X 0)) == NULL)
- X goto bombout;
- X
- X (void)strcpy(nbuf,path);
- X (void)strcat(nbuf,".dat");
- X
- X if((ret->st = store_open(nbuf,flags,mode)) == NULL)
- X goto bombout;
- X
- X /* OK */
- X btdbm_clearerror(ret);
- X return(ret);
- X
- Xbombout:
- X free((char *)ret);
- X return(NULL);
- X}
- END_OF_FILE
- if test 1192 -ne `wc -c <'b+tree/btdbmlib/btdbmopen.c'`; then
- echo shar: \"'b+tree/btdbmlib/btdbmopen.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/btdbmopen.c'
- fi
- if test -f 'b+tree/btdbmlib/btdbmstore.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/btdbmstore.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/btdbmstore.c'\" \(1217 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/btdbmstore.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <btdbm.h>
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/btdbmstore.c,v 1.1 89/10/24 10:09:12 mjr Rel $";
- X#endif
- X
- X
- Xbtdbm_store(db,key,data,flag)
- XBTDBM *db;
- Xbtdatum key;
- Xbtdatum data;
- Xint flag;
- X{
- X off_t orrv;
- X
- X btdbm_error(db) = 1;
- X if(bt_find(db->bt,key.dptr,key.dsize,&orrv) != BT_NF) {
- X if(flag == BTDBM_INSERT) {
- X return(1);
- X } else {
- X /* free old stored record */
- X if(store_free(db->st,orrv) == STO_ERR)
- X return(1);
- X }
- X }
- X
- X /* allocate new record */
- X if((orrv = store_alloc(db->st,data.dsize)) == STO_ERR)
- X return(1);
- X
- X /* copy data into new record */
- X if(store_write(db->st,orrv,0L,data.dptr,data.dsize) == STO_ERR)
- X return(1);
- X
- X /* update pointer in the b+tree - ok at this point to just replace */
- X if(bt_insert(db->bt,key.dptr,key.dsize,orrv,1) == BT_ERR)
- X return(1);
- X
- X btdbm_clearerror(db);
- X return(0);
- X}
- END_OF_FILE
- if test 1217 -ne `wc -c <'b+tree/btdbmlib/btdbmstore.c'`; then
- echo shar: \"'b+tree/btdbmlib/btdbmstore.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/btdbmstore.c'
- fi
- if test -f 'b+tree/btdbmlib/stclose.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stclose.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stclose.c'\" \(787 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stclose.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stclose.c,v 1.1 89/10/24 10:09:13 mjr Rel $";
- X#endif
- X
- X/*
- X close a store file and deallocate any buffers, etc
- X*/
- X
- Xstore_close(r)
- XSTORE *r;
- X{
- X int rv = STO_OK;
- X
- X if(close(store_fileno(r)) != 0)
- X rv = STO_ERR;
- X
- X if(store_buffer(r) != NULL)
- X free((char *)store_buffer(r));
- X free((char *)r);
- X return(rv);
- X}
- END_OF_FILE
- if test 787 -ne `wc -c <'b+tree/btdbmlib/stclose.c'`; then
- echo shar: \"'b+tree/btdbmlib/stclose.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stclose.c'
- fi
- if test -f 'b+tree/btdbmlib/stcopy.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stcopy.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stcopy.c'\" \(1260 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stcopy.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stcopy.c,v 1.1 89/10/24 10:09:13 mjr Rel $";
- X#endif
- X
- X/*
- X make a copy of a record. returns an error if there is not enough
- X space for the copy. otherwise it will read and write buffers as
- X necessary to copy the entire IN-USE portion of a record. bytes
- X that are not in-use are not copied, which allows records to be
- X "shrunk" in this manner.
- X*/
- X
- Xstore_copy(r,rec1,rec2)
- XSTORE *r;
- Xsto_ptr rec1;
- Xsto_ptr rec2;
- X{
- X off_t currof = 0L;
- X
- X if(rec1 == rec2)
- X return(STO_OK);
- X
- X while(1) {
- X int ismore;
- X int byts;
- X
- X ismore = store_read(r,rec1,currof,store_buffer(r),store_bufsiz(r),&byts);
- X if(ismore == STO_ERR)
- X return(STO_ERR);
- X
- X if(store_write(r,rec2,currof,store_buffer(r),byts) == STO_ERR)
- X return(STO_ERR);
- X
- X currof += (off_t)byts;
- X
- X if(ismore == STO_OK)
- X break;
- X }
- X return(STO_OK);
- X}
- END_OF_FILE
- if test 1260 -ne `wc -c <'b+tree/btdbmlib/stcopy.c'`; then
- echo shar: \"'b+tree/btdbmlib/stcopy.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stcopy.c'
- fi
- if test -f 'b+tree/btdbmlib/stdecref.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stdecref.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stdecref.c'\" \(804 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stdecref.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stdecref.c,v 1.1 89/10/24 10:09:13 mjr Rel $";
- X#endif
- X
- X/*
- X decrement the reference count in a record header.
- X*/
- X
- Xstore_decrefcnt(r,rec)
- XSTORE *r;
- Xsto_ptr rec;
- X{
- X struct sto_hdr rbuf;
- X if(store_gethdr(r,rec,&rbuf) == STO_ERR)
- X return(STO_ERR);
- X rbuf.refs--;
- X if(store_puthdr(r,rec,&rbuf) == STO_ERR)
- X return(STO_ERR);
- X return(STO_OK);
- X}
- END_OF_FILE
- if test 804 -ne `wc -c <'b+tree/btdbmlib/stdecref.c'`; then
- echo shar: \"'b+tree/btdbmlib/stdecref.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stdecref.c'
- fi
- if test -f 'b+tree/btdbmlib/sterrs.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/sterrs.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/sterrs.c'\" \(1342 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/sterrs.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/sterrs.c,v 1.1 89/10/24 10:09:14 mjr Rel $";
- X#endif
- X
- X/*
- X error strings and a perror() like routine.
- X*/
- X
- Xextern int errno;
- X
- Xchar *sto_errs[] = {
- X/* STO_NOERROR */ "no record error",
- X/* STO_BADHDR */ "bad record header",
- X/* STO_IOERR */ "record I/O error",
- X/* STO_NOSTO */ "no such record",
- X/* STO_TOOSMALL */ "record too small",
- X0};
- X
- X
- Xvoid
- Xstore_perror(r,s)
- XSTORE *r;
- Xchar *s;
- X{
- X static char *cmesg = "cannot open";
- X static char *fmt1 = "%s\n";
- X static char *fmt2 = "%s: %s\n";
- X
- X if(r == NULL) {
- X if(s == NULL || *s == '\0')
- X (void)fprintf(stderr,fmt1,cmesg);
- X else
- X (void)fprintf(stderr,fmt2,s,cmesg);
- X return;
- X }
- X if(store_errno(r) == STO_NOERROR && errno != 0) {
- X perror(s);
- X } else {
- X if(s == NULL || *s == '\0')
- X (void)fprintf(stderr,fmt1,sto_errs[store_errno(r)]);
- X else
- X (void)fprintf(stderr,fmt2,s,sto_errs[store_errno(r)]);
- X }
- X}
- END_OF_FILE
- if test 1342 -ne `wc -c <'b+tree/btdbmlib/sterrs.c'`; then
- echo shar: \"'b+tree/btdbmlib/sterrs.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/sterrs.c'
- fi
- if test -f 'b+tree/btdbmlib/stgethed.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stgethed.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stgethed.c'\" \(1468 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stgethed.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X#include "stointern.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stgethed.c,v 1.1 89/10/24 10:09:15 mjr Rel $";
- X#endif
- X
- X/*
- X read a record header. this might benefit from some caching,
- X because this function is called A LOT. a record header is
- X read, then checked (as much as we can - using a magic number)
- X for validity. note that the file descriptor should be left
- X pointing to the beginning of the record's data segment. the
- X functions store_read() and store_write() rely on this.
- X*/
- X
- Xextern off_t lseek();
- X
- Xstore_gethdr(r,rec,hdr)
- XSTORE *r;
- Xsto_ptr rec;
- Xstruct sto_hdr *hdr;
- X{
- X if(rec == STO_NULL) {
- X store_errno(r) = STO_NOREC;
- X return(STO_ERR);
- X }
- X
- X if(lseek(store_fileno(r),rec,SEEK_SET) != rec) {
- X store_errno(r) = STO_IOERR;
- X return(STO_ERR);
- X }
- X
- X switch(read(store_fileno(r),(char *)hdr,STO_HSIZ)) {
- X case 0:
- X store_errno(r) = STO_NOREC;
- X return(STO_ERR);
- X
- X case STO_HSIZ:
- X if(hdr->magic != STO_DFLTMAGIC) {
- X store_errno(r) = STO_NOREC;
- X return(STO_ERR);
- X }
- X return(STO_OK);
- X
- X default:
- X return(STO_ERR);
- X }
- X
- X}
- END_OF_FILE
- if test 1468 -ne `wc -c <'b+tree/btdbmlib/stgethed.c'`; then
- echo shar: \"'b+tree/btdbmlib/stgethed.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stgethed.c'
- fi
- if test -f 'b+tree/btdbmlib/stincref.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stincref.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stincref.c'\" \(798 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stincref.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stincref.c,v 1.1 89/10/24 10:09:15 mjr Rel $";
- X#endif
- X
- X/*
- X increment a reference counter in the header
- X*/
- X
- Xstore_increfcnt(r,rec)
- XSTORE *r;
- Xsto_ptr rec;
- X{
- X struct sto_hdr rbuf;
- X if(store_gethdr(r,rec,&rbuf) == STO_ERR)
- X return(STO_ERR);
- X rbuf.refs++;
- X if(store_puthdr(r,rec,&rbuf) == STO_ERR)
- X return(STO_ERR);
- X return(STO_OK);
- X}
- END_OF_FILE
- if test 798 -ne `wc -c <'b+tree/btdbmlib/stincref.c'`; then
- echo shar: \"'b+tree/btdbmlib/stincref.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stincref.c'
- fi
- if test -f 'b+tree/btdbmlib/stlinka.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stlinka.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stlinka.c'\" \(1609 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stlinka.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stlinka.c,v 1.1 89/10/24 10:09:15 mjr Rel $";
- X#endif
- X
- X/*
- X manipulate the link pointers of a header to link the record numbered
- X 'pred' AFTER the record numbered 'victim'. Note that no attempt is
- X made to UNLINK the victim if it is already linked into a list.
- X that must be controlled at a higher level, or we get into a kind
- X of recursive linking and unlinking loop and never return.
- X*/
- X
- Xstore_linkafter(r,victim,pred)
- XSTORE *r;
- Xsto_ptr victim;
- Xsto_ptr pred;
- X{
- X struct sto_hdr nbuf;
- X struct sto_hdr pbuf;
- X struct sto_hdr vbuf;
- X char nnul = 0;
- X
- X if(pred == STO_NULL) {
- X store_errno(r) = STO_NOREC;
- X return(STO_ERR);
- X }
- X
- X if(store_gethdr(r,victim,&vbuf) == STO_ERR || store_gethdr(r,pred,&pbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X if(pbuf.next != STO_NULL)
- X nnul++;
- X
- X if(nnul && store_gethdr(r,pbuf.next,&nbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X if(nnul)
- X nbuf.prev = victim;
- X
- X vbuf.prev = pred;
- X vbuf.next = pbuf.next;
- X pbuf.next = victim;
- X
- X if(store_puthdr(r,victim,&vbuf) == STO_ERR || store_puthdr(r,pred,&pbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X if(nnul && store_puthdr(r,vbuf.next,&nbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X return(STO_OK);
- X}
- END_OF_FILE
- if test 1609 -ne `wc -c <'b+tree/btdbmlib/stlinka.c'`; then
- echo shar: \"'b+tree/btdbmlib/stlinka.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stlinka.c'
- fi
- if test -f 'b+tree/btdbmlib/stoconf.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stoconf.h'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stoconf.h'\" \(946 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stoconf.h' <<'END_OF_FILE'
- X#ifndef _DEF_STO_CONF_H
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X/*
- X $Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stoconf.h,v 1.1 89/10/24 10:09:20 mjr Rel $
- X
- X THIS SHOULD NOT BE INCLUDED BY USER-LEVEL PROGRAMS
- X
- X All reasonably user-configurable options are in this file.
- X
- X If there is something that needs to be special-cased for
- X a system, put it here, PLEASE!
- X*/
- X
- X
- X/*
- Xdefault magic number to use for a record store file
- X*/
- X#define STO_DFLTMAGIC 0x72252
- X
- X
- X/*
- XSEEK_SET should be whatever your systems version of lseek() takes
- Xto tell it to go to an exact offset. zero is pretty standard.
- X*/
- X#ifndef SEEK_SET
- X#define SEEK_SET 0
- X#endif
- X
- X#define _DEF_STO_CONF_H
- X#endif
- END_OF_FILE
- if test 946 -ne `wc -c <'b+tree/btdbmlib/stoconf.h'`; then
- echo shar: \"'b+tree/btdbmlib/stoconf.h'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stoconf.h'
- fi
- if test -f 'b+tree/btdbmlib/stointern.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stointern.h'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stointern.h'\" \(1431 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stointern.h' <<'END_OF_FILE'
- X#ifndef _DEF_STO_INTERN_H
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X/*
- X $Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stointern.h,v 1.1 89/10/24 10:09:21 mjr Rel $
- X THIS SHOULD NOT BE INCLUDED BY USER-LEVEL PROGRAMS
- X*/
- X
- X
- X/*
- X macros to control the layout of a free list buffer
- X*/
- Xstruct sto_freeent {
- X sto_ptr addr;
- X int size;
- X};
- X
- X/* the next free list buffer in chain */
- X#define STO_FREENXT(b) (*(off_t *)(b))
- X
- X/* the number of free list entries in this buffer */
- X#define STO_FREECNT(b) (*(int *)(b + sizeof(off_t)))
- X
- X/* the actual data area - note this is inherently aligned to an off_t */
- X#define STO_FREEBUF(b) ((struct sto_freeent *)(b + (2 * sizeof(off_t))))
- X
- X/* size of a record header, for the sake of abberviation */
- X#define STO_HSIZ (sizeof(struct sto_hdr))
- X
- X/* size of a freelist entry, for the sake of abberviation */
- X#define STO_FSIZ (sizeof(struct sto_freeent))
- X
- X/*
- Xsize at which to start fragmenting records internally. If the record
- Xcan be split, and have at least this much left, it will. Note that
- Xthe remaining value MUST include room for a record header block
- X*/
- X#define STO_SPLITSIZ (265 + STO_HSIZ)
- X
- X#define _DEF_STO_INTERN_H
- X#endif
- END_OF_FILE
- if test 1431 -ne `wc -c <'b+tree/btdbmlib/stointern.h'`; then
- echo shar: \"'b+tree/btdbmlib/stointern.h'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stointern.h'
- fi
- if test -f 'b+tree/btdbmlib/stopen.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stopen.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stopen.c'\" \(1552 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stopen.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <sys/file.h>
- X#include "stoconf.h"
- X#include "store.h"
- X#include "stointern.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stopen.c,v 1.1 89/10/24 10:09:16 mjr Rel $";
- X#endif
- X
- X/*
- X open a store file and allocate all the buffers, etc.
- X*/
- X
- Xextern char *malloc();
- X
- XSTORE *
- Xstore_open(path,flags,mode)
- Xchar *path;
- Xint flags;
- Xint mode;
- X{
- X STORE *ret;
- X int r;
- X
- X if((ret = (STORE *)malloc(sizeof(STORE))) == NULL)
- X return(NULL);
- X
- X if((store_buffer(ret) = (unsigned char *)malloc((unsigned)STO_BUFSIZ)) == NULL)
- X return(NULL);
- X store_bufsiz(ret) = STO_BUFSIZ;
- X
- X if((store_fileno(ret) = open(path,flags|O_RDWR,mode)) < 0)
- X goto bombout;
- X
- X r = read(store_fileno(ret),(char *)&ret->sblk,sizeof(struct sto_sb));
- X
- X /* initialize */
- X if(r == 0) {
- X ret->sblk.magic = STO_DFLTMAGIC;
- X ret->sblk.high = (off_t)sizeof(struct sto_sb);
- X ret->sblk.free = STO_NULL;
- X ret->sblk.label = STO_NULL;
- X if(store_wsuper(ret) != STO_OK)
- X goto bombout;
- X }
- X
- X if(ret->sblk.magic != STO_DFLTMAGIC)
- X goto bombout;
- X
- X ret->currec = STO_NULL;
- X ret->curlst = STO_NULL;
- X
- X store_clearerr(ret);
- X
- X /* all is well. */
- X return(ret);
- X
- X bombout:
- X free((char *)ret);
- X return(NULL);
- X}
- END_OF_FILE
- if test 1552 -ne `wc -c <'b+tree/btdbmlib/stopen.c'`; then
- echo shar: \"'b+tree/btdbmlib/stopen.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stopen.c'
- fi
- if test -f 'b+tree/btdbmlib/stputhed.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stputhed.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stputhed.c'\" \(960 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stputhed.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X#include "stointern.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stputhed.c,v 1.1 89/10/24 10:09:17 mjr Rel $";
- X#endif
- X
- X/*
- X update a record header. this function is also called a lot and
- X should be (maybe) made to cache and synchronise with store_gethdr().
- X*/
- X
- Xextern off_t lseek();
- X
- Xstore_puthdr(r,rec,hdr)
- XSTORE *r;
- Xsto_ptr rec;
- Xstruct sto_hdr *hdr;
- X{
- X if(lseek(store_fileno(r),rec,SEEK_SET) != rec ||
- X write(store_fileno(r),(char *)hdr,STO_HSIZ) != STO_HSIZ) {
- X store_errno(r) = STO_IOERR;
- X return(STO_ERR);
- X }
- X return(STO_OK);
- X}
- END_OF_FILE
- if test 960 -ne `wc -c <'b+tree/btdbmlib/stputhed.c'`; then
- echo shar: \"'b+tree/btdbmlib/stputhed.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stputhed.c'
- fi
- if test -f 'b+tree/btdbmlib/stread.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stread.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stread.c'\" \(1414 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stread.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X#include "stointern.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stread.c,v 1.1 89/10/24 10:09:17 mjr Rel $";
- X#endif
- X
- X/*
- X function to read a record into a user-provided buffer. it is somewhat
- X like the read(2) system call except it accepts an offset, and returns
- X the number of bytes read in an integer variable provided by the caller.
- X*/
- X
- Xextern off_t lseek();
- X
- Xstore_read(r,rec,offset,buf,siz,rsiz)
- XSTORE *r;
- Xsto_ptr rec;
- Xoff_t offset;
- Xunsigned char *buf;
- Xint siz;
- Xint *rsiz;
- X{
- X struct sto_hdr rbuf;
- X int ret = STO_OK;
- X int toread;
- X
- X if(store_gethdr(r,rec,&rbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X if(rbuf.used > siz + offset)
- X ret = STO_MORE;
- X
- X if(siz + offset > rbuf.used)
- X toread = rbuf.used - offset;
- X else
- X toread = siz;
- X
- X if(offset > 0 && lseek(store_fileno(r),rec + STO_HSIZ + offset,SEEK_SET) != rec + STO_HSIZ + offset) {
- X store_errno(r) = STO_IOERR;
- X return(STO_ERR);
- X }
- X
- X if((*rsiz = read(store_fileno(r),(char *)buf,toread)) != toread)
- X return(STO_ERR);
- X return(ret);
- X}
- END_OF_FILE
- if test 1414 -ne `wc -c <'b+tree/btdbmlib/stread.c'`; then
- echo shar: \"'b+tree/btdbmlib/stread.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stread.c'
- fi
- if test -f 'b+tree/btdbmlib/streallocbuf.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/streallocbuf.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/streallocbuf.c'\" \(811 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/streallocbuf.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X#include "stointern.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/streallocbuf.c,v 1.1 89/10/24 10:09:18 mjr Rel $";
- X#endif
- X
- X
- Xextern char *realloc();
- X
- Xstore_reallocbuf(r,siz)
- XSTORE *r;
- Xint siz;
- X{
- X store_buffer(r) = (unsigned char *)realloc((char *)store_buffer(r),(unsigned)siz);
- X if(store_buffer(r) == NULL)
- X return(STO_ERR);
- X store_bufsiz(r) = siz;
- X return(STO_OK);
- X}
- END_OF_FILE
- if test 811 -ne `wc -c <'b+tree/btdbmlib/streallocbuf.c'`; then
- echo shar: \"'b+tree/btdbmlib/streallocbuf.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/streallocbuf.c'
- fi
- if test -f 'b+tree/btdbmlib/stunlink.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stunlink.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stunlink.c'\" \(1457 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stunlink.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stunlink.c,v 1.1 89/10/24 10:09:18 mjr Rel $";
- X#endif
- X
- X/*
- X break the links on both sides of a record, making them point to
- X the correct places.
- X*/
- X
- Xstore_unlink(r,victim)
- XSTORE *r;
- Xsto_ptr victim;
- X{
- X struct sto_hdr pbuf;
- X struct sto_hdr nbuf;
- X struct sto_hdr vbuf;
- X sto_ptr savprev;
- X sto_ptr savnext;
- X char pnul = 0;
- X char nnul = 0;
- X
- X if(store_gethdr(r,victim,&vbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X if((savnext = vbuf.next) != STO_NULL)
- X nnul++;
- X if((savprev = vbuf.prev) != STO_NULL)
- X pnul++;
- X
- X if(nnul && store_gethdr(r,vbuf.next,&nbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X if(pnul && store_gethdr(r,vbuf.prev,&pbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X if(nnul)
- X nbuf.prev = vbuf.prev;
- X if(pnul)
- X pbuf.next = vbuf.next;
- X
- X vbuf.prev = vbuf.next = STO_NULL;
- X
- X if(store_puthdr(r,victim,&vbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X if(pnul && store_puthdr(r,savprev,&pbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X if(nnul && store_puthdr(r,savnext,&nbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X return(STO_OK);
- X}
- END_OF_FILE
- if test 1457 -ne `wc -c <'b+tree/btdbmlib/stunlink.c'`; then
- echo shar: \"'b+tree/btdbmlib/stunlink.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stunlink.c'
- fi
- if test -f 'b+tree/btdbmlib/stwrite.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stwrite.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stwrite.c'\" \(1482 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stwrite.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X#include "stointern.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stwrite.c,v 1.1 89/10/24 10:09:19 mjr Rel $";
- X#endif
- X
- X/*
- X write(2)-like interface to write a record. accepts an offset, which
- X is treated as the point at which to start writing. if the write
- X extends the in-use space of the block, the header may be adjusted.
- X*/
- X
- Xextern off_t lseek();
- X
- Xstore_write(r,rec,offset,buf,siz)
- XSTORE *r;
- Xsto_ptr rec;
- Xoff_t offset;
- Xunsigned char *buf;
- Xint siz;
- X{
- X struct sto_hdr rbuf;
- X
- X if(store_gethdr(r,rec,&rbuf) == STO_ERR)
- X return(STO_ERR);
- X
- X if(siz > rbuf.size || (int)offset + siz > rbuf.size) {
- X store_errno(r) = STO_TOOSMALL;
- X return(STO_ERR);
- X }
- X
- X if(offset > 0 && lseek(store_fileno(r),rec + STO_HSIZ + offset,SEEK_SET) != rec + STO_HSIZ + offset) {
- X store_errno(r) = STO_IOERR;
- X return(STO_ERR);
- X }
- X
- X if(write(store_fileno(r),(char *)buf,siz) != siz)
- X return(STO_ERR);
- X
- X /* has the buffer grown any ? */
- X if(offset + siz > rbuf.used) {
- X rbuf.used = offset + siz;
- X if(store_puthdr(r,rec,&rbuf) == STO_ERR)
- X return(STO_ERR);
- X }
- X return(STO_OK);
- X}
- END_OF_FILE
- if test 1482 -ne `wc -c <'b+tree/btdbmlib/stwrite.c'`; then
- echo shar: \"'b+tree/btdbmlib/stwrite.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stwrite.c'
- fi
- if test -f 'b+tree/btdbmlib/stwsuper.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btdbmlib/stwsuper.c'\"
- else
- echo shar: Extracting \"'b+tree/btdbmlib/stwsuper.c'\" \(791 characters\)
- sed "s/^X//" >'b+tree/btdbmlib/stwsuper.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include "stoconf.h"
- X#include "store.h"
- X
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btdbmlib/RCS/stwsuper.c,v 1.1 89/10/24 10:09:19 mjr Rel $";
- X#endif
- X
- X/*
- X synchronise a store file superblock.
- X*/
- X
- Xextern off_t lseek();
- X
- Xstore_wsuper(r)
- XSTORE *r;
- X{
- X if(lseek(store_fileno(r),0L,SEEK_SET) != 0L ||
- X write(store_fileno(r),(char *)&r->sblk,sizeof(struct sto_sb)) != sizeof(struct sto_sb))
- X return(STO_ERR);
- X return(STO_OK);
- X}
- END_OF_FILE
- if test 791 -ne `wc -c <'b+tree/btdbmlib/stwsuper.c'`; then
- echo shar: \"'b+tree/btdbmlib/stwsuper.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btdbmlib/stwsuper.c'
- fi
- if test ! -d 'b+tree/btlib' ; then
- echo shar: Creating directory \"'b+tree/btlib'\"
- mkdir 'b+tree/btlib'
- fi
- if test -f 'b+tree/btlib/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btlib/Makefile'\"
- else
- echo shar: Extracting \"'b+tree/btlib/Makefile'\" \(1408 characters\)
- sed "s/^X//" >'b+tree/btlib/Makefile' <<'END_OF_FILE'
- X#
- X#
- X#/*
- X# (C) Copyright, 1988, 1989 Marcus J. Ranum
- X# All rights reserved
- X#
- X#
- X# This software, its documentation, and supporting
- X# files are copyrighted material and may only be
- X# distributed in accordance with the terms listed in
- X# the COPYRIGHT document.
- X#*/
- X#
- X# $Header: /atreus/mjr/hacks/btree/btlib/RCS/Makefile,v 1.1 89/10/24 10:09:08 mjr Rel $
- X#
- X
- X# compiler to use
- XCC= cc
- X
- X# compiler flags
- X#CFLAGS= -p
- XCFLAGS= -O
- X
- XLDFLAGS= -g
- X
- X# where to build the library. must be set in testrack/Makefile
- X# if you change it from here.
- XLIBDIR=..
- XLIB= $(LIBDIR)/libbtree.a
- X
- XCFILES= btclose.c \
- X btdebug.c \
- X btdelete.c \
- X bterrors.c \
- X btfind.c \
- X btgoto.c \
- X btinsert.c \
- X btio.c \
- X btlabel.c \
- X btload.c \
- X btopen.c \
- X btoopen.c \
- X btpage1.c \
- X btpage2.c \
- X btravrs.c \
- X btseek.c \
- X btzap.c
- X
- XHFILES= btconf.h \
- X btree.h \
- X btintern.h
- X
- XOFILES= btclose.o \
- X btdebug.o \
- X btdelete.o \
- X bterrors.o \
- X btfind.o \
- X btgoto.o \
- X btio.o \
- X btinsert.o \
- X btlabel.o \
- X btload.o \
- X btopen.o \
- X btoopen.o \
- X btpage1.o \
- X btpage2.o \
- X btravrs.o \
- X btseek.o \
- X btzap.o
- X
- XFILES= $(CFILES) \
- X $(HFILES) \
- X README \
- X Makefile
- X
- X$(LIB): $(OFILES)
- X ar crv $(LIB) $(OFILES)
- X ranlib $(LIB)
- X
- X$(OFILES): $(HFILES)
- X
- Xclean:
- X rm -f *.o $(LIB) core tags
- X
- Xci:
- X ci -u $(FILES) < /dev/null
- X
- Xtags:
- X ctags $(CFILES)
- X
- Xlint: $(CFILES)
- X lint -u $(CFILES) | sed '/pointer alignment/d'
- END_OF_FILE
- if test 1408 -ne `wc -c <'b+tree/btlib/Makefile'`; then
- echo shar: \"'b+tree/btlib/Makefile'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btlib/Makefile'
- fi
- if test -f 'b+tree/btlib/btclose.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btlib/btclose.c'\"
- else
- echo shar: Extracting \"'b+tree/btlib/btclose.c'\" \(1075 characters\)
- sed "s/^X//" >'b+tree/btlib/btclose.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <stdio.h>
- X#include "btconf.h"
- X#include "btree.h"
- X#include "btintern.h"
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btlib/RCS/btclose.c,v 1.1 89/10/24 10:08:55 mjr Rel $";
- X#endif
- X
- Xbt_close(b)
- XBT_INDEX *b;
- X{
- X struct bt_cache *p1;
- X struct bt_cache *p2;
- X int rv;
- X
- X rv = bt_sync(b);
- X
- X /* close fd */
- X if(bt_fileno(b) != -1)
- X if(close(bt_fileno(b)) < 0)
- X rv = BT_ERR;
- X
- X /* free stack */
- X if(b->stack != NULL)
- X (void)free((char *)b->stack);
- X
- X /* free cache */
- X for(p1 = b->lru; p1 != NULL;) {
- X
- X /* K&R say not to use free()d stuff */
- X p2 = p1->next;
- X
- X /* free it */
- X (void)free((char *)p1->p);
- X (void)free((char *)p1);
- X p1 = p2;
- X }
- X
- X /* free handle itself */
- X (void)free((char *)b);
- X return(rv);
- X}
- END_OF_FILE
- if test 1075 -ne `wc -c <'b+tree/btlib/btclose.c'`; then
- echo shar: \"'b+tree/btlib/btclose.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btlib/btclose.c'
- fi
- if test -f 'b+tree/btlib/bterrors.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btlib/bterrors.c'\"
- else
- echo shar: Extracting \"'b+tree/btlib/bterrors.c'\" \(1580 characters\)
- sed "s/^X//" >'b+tree/btlib/bterrors.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <stdio.h>
- X#include "btconf.h"
- X#include "btree.h"
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btlib/RCS/bterrors.c,v 1.1 89/10/24 10:08:56 mjr Rel $";
- X#endif
- X
- X
- Xchar *bt_errs[] = {
- X/* BT_NOERROR */ "no btree error",
- X/* BT_KTOBIG */ "btree key too big",
- X/* BT_ZEROKEY */ "zero sized btree key",
- X/* BT_DUPKEY */ "duplicate btree key",
- X/* BT_PTRINVAL */ "invalid btree pointer",
- X/* BT_NOBUFFERS */ "insufficient btree buffers",
- X/* BT_LTOOBIG */ "btree label too big",
- X/* BT_BTOOSMALL */ "btree buffer too small",
- X/* BT_BADPAGE */ "btree page is corrupt",
- X/* BT_PAGESRCH */ "cannot search btree page",
- X/* BT_BADUSERARG */ "invalid btree argument",
- X0};
- X
- X/* system error # */
- Xextern int errno;
- X
- Xvoid
- Xbt_perror(b,s)
- XBT_INDEX *b;
- Xchar *s;
- X{
- X static char *cmesg = "cannot open";
- X static char *fmt1 = "%s\n";
- X static char *fmt2 = "%s: %s\n";
- X
- X if(b == NULL) {
- X if(s == NULL || *s == '\0')
- X (void)fprintf(stderr,fmt1,cmesg);
- X else
- X (void)fprintf(stderr,fmt2,s,cmesg);
- X return;
- X }
- X if(bt_errno(b) == BT_NOERROR && errno != 0) {
- X perror(s);
- X } else {
- X if(s == NULL || *s == '\0')
- X (void)fprintf(stderr,fmt1,bt_errs[bt_errno(b)]);
- X else
- X (void)fprintf(stderr,fmt2,s,bt_errs[bt_errno(b)]);
- X }
- X}
- END_OF_FILE
- if test 1580 -ne `wc -c <'b+tree/btlib/bterrors.c'`; then
- echo shar: \"'b+tree/btlib/bterrors.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btlib/bterrors.c'
- fi
- if test -f 'b+tree/btlib/btfind.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btlib/btfind.c'\"
- else
- echo shar: Extracting \"'b+tree/btlib/btfind.c'\" \(1226 characters\)
- sed "s/^X//" >'b+tree/btlib/btfind.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <stdio.h>
- X#include "btconf.h"
- X#include "btree.h"
- X#include "btintern.h"
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btlib/RCS/btfind.c,v 1.1 89/10/24 10:08:57 mjr Rel $";
- X#endif
- X
- Xbt_find(b,key,len,rrn)
- XBT_INDEX *b;
- Xbt_chrp key;
- Xint len;
- Xoff_t *rrn;
- X{
- X struct bt_cache *op; /* old page */
- X int sr;
- X
- X if(len > BT_MAXK(b)) {
- X bt_errno(b) == BT_KTOOBIG;
- X return(BT_ERR);
- X }
- X
- X if(len <= 0) {
- X bt_errno(b) == BT_ZEROKEY;
- X return(BT_ERR);
- X }
- X
- X if(bt_seekdown(b,key,len) == BT_ERR)
- X return(BT_ERR);
- X
- X if((op = bt_rpage(b,b->stack[b->sblk.levs - 1].pg)) == NULL)
- X return(BT_ERR);
- X
- X b->cpag = op->num;
- X
- X /* mark all as well with tree */
- X bt_clearerr(b);
- X
- X sr = bt_srchpg(key,len,bt_dtype(b),b->cmpfn,rrn,&b->cky,op->p);
- X if(sr == BT_OK)
- X return(BT_OK);
- X if(sr == BT_ERR) {
- X bt_errno(b) = BT_PAGESRCH;
- X return(BT_ERR);
- X }
- X b->cky--;
- X return(BT_NF);
- X}
- END_OF_FILE
- if test 1226 -ne `wc -c <'b+tree/btlib/btfind.c'`; then
- echo shar: \"'b+tree/btlib/btfind.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btlib/btfind.c'
- fi
- if test -f 'b+tree/btlib/btgoto.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btlib/btgoto.c'\"
- else
- echo shar: Extracting \"'b+tree/btlib/btgoto.c'\" \(1571 characters\)
- sed "s/^X//" >'b+tree/btlib/btgoto.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <stdio.h>
- X#include "btconf.h"
- X#include "btree.h"
- X#include "btintern.h"
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btlib/RCS/btgoto.c,v 1.1 89/10/24 10:08:58 mjr Rel $";
- X#endif
- X
- X
- Xextern char *realloc();
- X
- Xbt_goto(b,d)
- XBT_INDEX *b;
- Xint d;
- X{
- X int l = 0;
- X struct bt_cache *p;
- X
- X b->stack[0].pg = b->sblk.root;
- X
- X while(1) {
- X if((p = bt_rpage(b,b->stack[l].pg)) == NULL)
- X return(BT_ERR);
- X
- X /* dynamically deal w/ stack overruns */
- X if(l == b->shih - 2) {
- X b->shih += 3;
- X b->stack = (struct bt_stack *)realloc((char *)b->stack,(unsigned)(b->shih * sizeof(struct bt_stack)));
- X if(b->stack == NULL)
- X return(BT_ERR);
- X }
- X
- X /* set the key to be one AFTER or BEFORE the real */
- X /* end of the tree. we preincrement keys when doing */
- X /* next so this is OK to do, though a bit hokey */
- X if(HIPT(p->p) == BT_NULL) {
- X b->cpag = p->num;
- X if(d == BT_EOF)
- X b->cky = KEYCNT(p->p);
- X else
- X b->cky = -1;
- X
- X /* mark all as well with tree */
- X bt_clearerr(b);
- X return(BT_OK);
- X }
- X
- X /* have not yet hit a leaf - go high or low, as approp. */
- X if(d == BT_EOF || KEYCNT(p->p) == 0) {
- X b->stack[++l].pg = HIPT(p->p);
- X } else {
- X b->stack[++l].pg = *(off_t *)KEYCLD(p->p);
- X }
- X }
- X}
- END_OF_FILE
- if test 1571 -ne `wc -c <'b+tree/btlib/btgoto.c'`; then
- echo shar: \"'b+tree/btlib/btgoto.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btlib/btgoto.c'
- fi
- if test -f 'b+tree/btlib/btlabel.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btlib/btlabel.c'\"
- else
- echo shar: Extracting \"'b+tree/btlib/btlabel.c'\" \(1264 characters\)
- sed "s/^X//" >'b+tree/btlib/btlabel.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <sys/file.h>
- X#include "btconf.h"
- X#include "btree.h"
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btlib/RCS/btlabel.c,v 1.1 89/10/24 10:08:59 mjr Rel $";
- X#endif
- X
- Xextern off_t lseek();
- X
- Xbt_wlabel(b,buf,siz)
- XBT_INDEX *b;
- Xbt_chrp buf;
- Xint siz;
- X{
- X if(siz > BT_LABSIZ(b)) {
- X bt_errno(b) = BT_LTOOBIG;
- X return(BT_ERR);
- X }
- X
- X if((lseek(bt_fileno(b),(off_t)sizeof(struct bt_super),SEEK_SET) !=
- X (off_t)sizeof(struct bt_super)) ||
- X (write(bt_fileno(b),(char *)buf,siz) != siz))
- X return(BT_ERR);
- X bt_clearerr(b);
- X return(BT_OK);
- X}
- X
- Xbt_rlabel(b,buf,siz)
- XBT_INDEX *b;
- Xbt_chrp buf;
- Xint siz;
- X{
- X if(siz < BT_LABSIZ(b)) {
- X bt_errno(b) = BT_BTOOSMALL;
- X return(BT_ERR);
- X }
- X
- X if((lseek(bt_fileno(b),(off_t)sizeof(struct bt_super),SEEK_SET) !=
- X (off_t)sizeof(struct bt_super)) ||
- X (read(bt_fileno(b),(char *)buf,BT_LABSIZ(b)) != BT_LABSIZ(b)))
- X return(BT_ERR);
- X bt_clearerr(b);
- X return(BT_OK);
- X}
- END_OF_FILE
- if test 1264 -ne `wc -c <'b+tree/btlib/btlabel.c'`; then
- echo shar: \"'b+tree/btlib/btlabel.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btlib/btlabel.c'
- fi
- if test -f 'b+tree/btlib/btseek.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btlib/btseek.c'\"
- else
- echo shar: Extracting \"'b+tree/btlib/btseek.c'\" \(1330 characters\)
- sed "s/^X//" >'b+tree/btlib/btseek.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <stdio.h>
- X#include "btconf.h"
- X#include "btree.h"
- X#include "btintern.h"
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btlib/RCS/btseek.c,v 1.1 89/10/24 10:09:06 mjr Rel $";
- X#endif
- X
- Xextern char *realloc();
- X
- Xbt_seekdown(b,key,len)
- XBT_INDEX *b;
- Xbt_chrp key;
- Xint len;
- X{
- X /* bt_find just seeks down to leaf level, sets the stack, ends */
- X
- X int l = 0;
- X int sr;
- X struct bt_cache *p;
- X
- X b->stack[0].pg = b->sblk.root;
- X
- X while(1) {
- X if((p = bt_rpage(b,b->stack[l].pg)) == NULL)
- X return(BT_ERR);
- X if(HIPT(p->p) == BT_NULL) {
- X return(BT_OK);
- X }
- X sr = bt_srchpg(key,len,bt_dtype(b),b->cmpfn,&b->stack[l + 1].pg,&b->stack[l].ky,p->p);
- X if(sr == BT_ERR) {
- X bt_errno(b) = BT_PAGESRCH;
- X return(BT_ERR);
- X }
- X
- X /* dynamically deal w/ stack overruns */
- X if(l == b->shih - 2) {
- X b->shih += 3;
- X b->stack = (struct bt_stack *)realloc((char *)b->stack,(unsigned)(b->shih * sizeof(struct bt_stack)));
- X if(b->stack == NULL)
- X return(BT_ERR);
- X }
- X
- X l++;
- X }
- X}
- END_OF_FILE
- if test 1330 -ne `wc -c <'b+tree/btlib/btseek.c'`; then
- echo shar: \"'b+tree/btlib/btseek.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btlib/btseek.c'
- fi
- if test -f 'b+tree/btlib/btzap.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/btlib/btzap.c'\"
- else
- echo shar: Extracting \"'b+tree/btlib/btzap.c'\" \(1212 characters\)
- sed "s/^X//" >'b+tree/btlib/btzap.c' <<'END_OF_FILE'
- X#include <sys/types.h>
- X#include <stdio.h>
- X#include "btconf.h"
- X#include "btree.h"
- X#include "btintern.h"
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- X#ifndef lint
- Xstatic char *rcsid = "$Header: /atreus/mjr/hacks/btree/btlib/RCS/btzap.c,v 1.1 89/10/24 10:09:06 mjr Rel $";
- X#endif
- X
- Xbt_zap(b)
- XBT_INDEX *b;
- X{
- X struct bt_cache *op;
- X
- X /* toast superblock */
- X b->sblk.levs = 1;
- X b->sblk.root = bt_pagesiz(b);
- X b->sblk.free = BT_NULL;
- X b->sblk.high = 2 * bt_pagesiz(b);
- X b->dirt++;
- X if(bt_wsuper(b) == BT_ERR)
- X return(BT_ERR);
- X
- X /* set up first leaf */
- X if((op = bt_rpage(b,BT_NULL)) == NULL)
- X return(BT_ERR);
- X
- X /* note - set cky and cpag case called by bt_load() */
- X op->num = b->sblk.root;
- X KEYCNT(op->p) = 0;
- X KEYLEN(op->p) = 0;
- X LSIB(op->p) = RSIB(op->p) = BT_NULL;
- X HIPT(op->p) = BT_NULL;
- X
- X op->flags = BT_CHE_DIRTY;
- X
- X#ifdef USE_FTRUNCATE
- X if(ftruncate(bt_fileno(b),b->sblk.high) == -1)
- X return(BT_ERR);
- X#endif
- X
- X return(bt_wpage(b,op));
- X}
- END_OF_FILE
- if test 1212 -ne `wc -c <'b+tree/btlib/btzap.c'`; then
- echo shar: \"'b+tree/btlib/btzap.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/btlib/btzap.c'
- fi
- if test ! -d 'b+tree/doc' ; then
- echo shar: Creating directory \"'b+tree/doc'\"
- mkdir 'b+tree/doc'
- fi
- if test -f 'b+tree/doc/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/doc/Makefile'\"
- else
- echo shar: Extracting \"'b+tree/doc/Makefile'\" \(815 characters\)
- sed "s/^X//" >'b+tree/doc/Makefile' <<'END_OF_FILE'
- X#
- X#
- X#/*
- X# (C) Copyright, 1988, 1989 Marcus J. Ranum
- X# All rights reserved
- X#
- X#
- X# This software, its documentation, and supporting
- X# files are copyrighted material and may only be
- X# distributed in accordance with the terms listed in
- X# the COPYRIGHT document.
- X#*/
- X#
- X# $Header: /atreus/mjr/hacks/btree/doc/RCS/Makefile,v 1.5 89/10/23 17:19:35 mjr Rel $
- X#
- X
- X# formatter to use
- XFMT= psroff
- X
- X# formatter flags
- XFMTFLAGS= -man
- X
- X# where to install the man pages.
- XMANDIR= /usr/man/man3
- XMAN= $(MANDIR)/btree.3
- X
- XDOCS= btdbm.3 \
- X btree.3 \
- X store.3
- X
- Xall:
- X
- Xclean:
- X rm -f store.txt btree.txt
- X
- Xci: clean
- X ci -u $(DOCS) Makefile < /dev/null
- X
- Xprint:
- X $(FMT) $(FMTFLAGS) $(DOCS)
- X
- Xascii:
- X nroff $(FMTFLAGS) btree.3 > btree.txt
- X nroff $(FMTFLAGS) store.3 > store.txt
- END_OF_FILE
- if test 815 -ne `wc -c <'b+tree/doc/Makefile'`; then
- echo shar: \"'b+tree/doc/Makefile'\" unpacked with wrong size!
- fi
- # end of 'b+tree/doc/Makefile'
- fi
- if test ! -d 'b+tree/utils' ; then
- echo shar: Creating directory \"'b+tree/utils'\"
- mkdir 'b+tree/utils'
- fi
- if test -f 'b+tree/utils/flog.sh' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/utils/flog.sh'\"
- else
- echo shar: Extracting \"'b+tree/utils/flog.sh'\" \(695 characters\)
- sed "s/^X//" >'b+tree/utils/flog.sh' <<'END_OF_FILE'
- X#
- X#/*
- X# (C) Copyright, 1988, 1989 Marcus J. Ranum
- X# All rights reserved
- X#
- X#
- X# This software, its documentation, and supporting
- X# files are copyrighted material and may only be
- X# distributed in accordance with the terms listed in
- X# the COPYRIGHT document.
- X#*/
- X
- Xcnt=1
- Xkeys=2000
- Xlengths=8
- Xpagesiz=61
- Xwhile [ 1 = 1 ]; do
- X echo "$keys keys for #$cnt ..."
- X words $keys $lengths > input
- X sort input | uniq > input.srt
- X echo "running #$cnt ..."
- X testrack input input.srt $pagesiz
- X if [ $? != 0 ]; then
- X echo " failed!"
- X echo "input producing the failure is left in \"input\""
- X exit 1
- X fi
- X echo "passed"
- X
- X cnt=`expr $cnt + 1`
- Xdone
- END_OF_FILE
- if test 695 -ne `wc -c <'b+tree/utils/flog.sh'`; then
- echo shar: \"'b+tree/utils/flog.sh'\" unpacked with wrong size!
- fi
- # end of 'b+tree/utils/flog.sh'
- fi
- if test -f 'b+tree/utils/words.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'b+tree/utils/words.c'\"
- else
- echo shar: Extracting \"'b+tree/utils/words.c'\" \(1027 characters\)
- sed "s/^X//" >'b+tree/utils/words.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X
- X/*
- X (C) Copyright, 1988, 1989 Marcus J. Ranum
- X All rights reserved
- X
- X
- X This software, its documentation, and supporting
- X files are copyrighted material and may only be
- X distributed in accordance with the terms listed in
- X the COPYRIGHT document.
- X*/
- X
- X
- Xextern long random();
- Xextern long time();
- X
- Xmain(ac,av)
- Xint ac;
- Xchar *av[];
- X{
- X char buf[BUFSIZ];
- X int todo;
- X int maxlen = 50;
- X int len;
- X long junk;
- X int x;
- X int y;
- X
- X (void)time(&junk);
- X (void)srandom((int)junk);
- X
- X if(ac < 3) {
- X (void)fprintf(stderr,"usage: words count [len]\n");
- X exit(1);
- X }
- X
- X /* how many inserts to perform */
- X todo = atoi(av[1]);
- X
- X if(ac > 2) {
- X maxlen = atoi(av[2]);
- X if(maxlen < 1) {
- X (void)fprintf(stderr,"max len less than 1 is stupid!\n");
- X exit(1);
- X }
- X }
- X
- X for(x = 0; x < todo; x++) {
- X len = ((int)random() % maxlen) + 1;
- X for(y = 0; y < len; y++)
- X buf[y] = ((int)random() % 25) + 'a';
- X
- X buf[len] = '\0';
- X (void)printf("%s\n",buf);
- X }
- X exit(0);
- X}
- END_OF_FILE
- if test 1027 -ne `wc -c <'b+tree/utils/words.c'`; then
- echo shar: \"'b+tree/utils/words.c'\" unpacked with wrong size!
- fi
- # end of 'b+tree/utils/words.c'
- fi
- echo shar: End of archive 1 \(of 5\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 2 3 4 5 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 5 archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-
-